package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.GridContainerEvent;
	import com.tongji.housediy.events.UpdateRatioCompEvent;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class ViewMoveMediator extends Mediator
	{
		[Inject]
		public var view:ViewMoveComp;
		
		override public function onRegister():void
		{
			view.leftButton.addEventListener(MouseEvent.MOUSE_DOWN, leftButtonMouseDownHandler);
			view.leftButton.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUpHandler);
			
			view.rightButton.addEventListener(MouseEvent.MOUSE_DOWN, rightButtonMouseDownHandler);
			view.rightButton.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUpHandler);
			
			view.upButton.addEventListener(MouseEvent.MOUSE_DOWN, upButtonMouseDownHandler);
			view.upButton.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUpHandler);
			
			view.downButton.addEventListener(MouseEvent.MOUSE_DOWN, downButtonMouseDownHandler);
			view.downButton.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUpHandler);
			
			view.retrieveButton.addEventListener(MouseEvent.CLICK, retrieveButtonClickHandler);
		}
		
		private function leftButtonMouseDownHandler(event:MouseEvent):void
		{
			dispatch(new GridContainerEvent(GridContainerEvent.START_MOVE_LEFT));
		}
		
		private function rightButtonMouseDownHandler(event:MouseEvent):void
		{
			dispatch(new GridContainerEvent(GridContainerEvent.START_MOVE_RIGHT));
		}
		
		private function upButtonMouseDownHandler(event:MouseEvent):void
		{
			dispatch(new GridContainerEvent(GridContainerEvent.START_MOVE_UP));
		}
		
		private function downButtonMouseDownHandler(event:MouseEvent):void
		{
			dispatch(new GridContainerEvent(GridContainerEvent.START_MOVE_DOWN));
		}
		
		private function buttonMouseUpHandler(event:MouseEvent):void
		{
			dispatch(new GridContainerEvent(GridContainerEvent.STOP_MOVE));
		}
		
		private function retrieveButtonClickHandler(event:MouseEvent):void
		{			
			dispatch(new GridContainerEvent(GridContainerEvent.RETRIEVE_GRID_CONTAINER));
			dispatch(new UpdateRatioCompEvent(UpdateRatioCompEvent.UPATE_RATIO_COMP, 4));
		}
	}
}